package eu.webhib.webblog.domain;

import javax.persistence.*;
import org.apache.log4j.Logger;

import eu.webhib.webblog.domain.base.CommonBaseEntityImpl;

//
@javax.persistence.Entity
@javax.persistence.NamedQueries({
   @javax.persistence.NamedQuery(name = "Comment_All", query = "SELECT c FROM Comment c")
})
@Access(AccessType.FIELD)
public class Comment extends CommonBaseEntityImpl {
   //
   private static final Logger log = Logger.getLogger(Comment.class);
   //
   private static final int DISPLAY_NAME_LEN = 18;
   // attributes
   @Column(nullable = false)
   private String text;
   // relations
   @ManyToOne(optional = true, fetch = FetchType.LAZY)
   private Comment parent;
   @ManyToOne(optional = false, fetch = FetchType.LAZY)
   private Posting posting;

   //
   // getter/setter
   //
   public String getLabel() {
      return text.substring(0, DISPLAY_NAME_LEN) + "...";
   }

   public String getText() {
      return text;
   }

   public void setText(String text) {
      this.text = text;
   }

   public Comment getParent() {
      return parent;
   }

   public void setParent(Comment parent) {
      this.parent = parent;
   }

   public Posting getPosting() {
      return posting;
   }

   public void setPosting(Posting posting) {
      this.posting = posting;
   }
}
